#!/bin/bash


filenum=0
for filename in $(ls)
do
    if [ -d $filename ] && [ $filename == "test" ]
    then
        filenum=1
    fi
done
if [ $filenum -eq 1 ] 
then
    read -p "检测到test文件夹,是否打开文件夹(y/n)" decision
else
    mkdir test
    read -p "已创建test文件夹,是否打开文件夹(y/n)" decision
fi

if [ $decision == y ] 
then
    cd test
    
    testnum=0
    for((i=0;i<3;i++));
    do      
        if [ $testnum -eq 1 ]  
        then
            read -p "请重新输入需要创建的文件名:" file
            testnum=0
        elif [ $testnum -eq 0 ]  
        then
            read -p "请输入需要创建的文件名:" file 
        fi         
        
        for tempfile in $(ls)
        do
            if [ $file == $tempfile ] 
            then
                testnum=1
            fi
        done
        if [ $testnum -eq 1 ] 
        then 
            echo "文件名已被占用,无法再次创建此文件"           
            continue
        elif [ $testnum -eq 0 ] 
        then
            touch $file
        fi
             
    done    
fi
